/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.UnitEnity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class UnitMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.selectAll
    
    public List<UnitEnity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_unit where `isEnabled`=1 and `ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new UnitEnity());
        return (List<UnitEnity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(UnitEnity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_unit set `code` = ?, `unitName` = ?, `unitGroup` = ?, `unitGroup_name` = ?, `truncationType` = ?, `precision` = ?, `bBaseUnit` = ?, `stopstatus` = ?, `isEnabled` = ?, `modifier` = ?, `modifyTime` = ?, `convertCoefficient` = ?, `pubts` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitName(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitGroup(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitGroup_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getTruncationType(), Types.INTEGER);
		parameter.addParamWithType(record.getPrecision(), Types.INTEGER);
		parameter.addParamWithType(record.getbBaseUnit(), Types.BIT);
		parameter.addParamWithType(record.getStopstatus(), Types.BIT);
		parameter.addParamWithType(record.getEnabled(), Types.BIT);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getConvertCoefficient(), Types.DECIMAL);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.insertBatch
    
    public int insertBatch(List<UnitEnity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_unit (`id`, `code`, `unitName`, `unitGroup`, `unitGroup_name`, `bBaseUnit`, `truncationType`, `precision`, `stopstatus`, `isEnabled`, `creator`,`modifier`, `createTime`, `modifyTime`, `ytenant_id`,`convertCoefficient`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				UnitEnity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitName(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitGroup(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitGroup_name(), Types.VARCHAR);
				parameter.addParamWithType(item.getbBaseUnit(), Types.BOOLEAN);
				parameter.addParamWithType(item.getTruncationType(), Types.INTEGER);
				parameter.addParamWithType(item.getPrecision(), Types.INTEGER);
				parameter.addParamWithType(item.getStopstatus(), Types.BOOLEAN);
				parameter.addParamWithType(item.getEnabled(), Types.BOOLEAN);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreateTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifyTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenantId(), Types.VARCHAR);
				parameter.addParamWithType(item.getConvertCoefficient(), Types.DECIMAL);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE `code`=VALUES(`code`), `unitName`=VALUES(`unitName`), `unitGroup`=VALUES(`unitGroup`), `unitGroup_name`=VALUES(`unitGroup_name`), `truncationType` = VALUES(`truncationType`), `precision` = VALUES(`precision`), `bBaseUnit`=VALUES(`bBaseUnit`), `stopstatus`=VALUES(`stopstatus`), `isEnabled`=VALUES(`isEnabled`), `convertCoefficient`=VALUES(`convertCoefficient`), `modifier`=VALUES(`modifier`), `createTime`=VALUES(`createTime`), `modifyTime`=VALUES(`modifyTime`) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_unit where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.insert
    
    public int insert(UnitEnity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_unit (`id`, `code`,  `unitName`, `unitGroup`,  `unitGroup_name`, `bBaseUnit`,  `truncationType`, `precision`,  `stopstatus`, `isEnabled`,  `creator`, `modifier`, `createTime`,  `modifyTime`, `pubts`,`ytenant_id`,`convertCoefficient`) values (?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitName(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitGroup(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitGroup_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getbBaseUnit(), Types.BIT);
		parameter.addParamWithType(record.getTruncationType(), Types.INTEGER);
		parameter.addParamWithType(record.getPrecision(), Types.INTEGER);
		parameter.addParamWithType(record.getStopstatus(), Types.BIT);
		parameter.addParamWithType(record.getEnabled(), Types.BIT);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantId(), Types.VARCHAR);
		parameter.addParamWithType(record.getConvertCoefficient(), Types.DECIMAL);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_unit where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitMapper.selectById
    
    public UnitEnity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_unit where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new UnitEnity());
        return (UnitEnity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

}
